package com.utn.ab.common.exception;

import com.utn.ab.common.entity.ResultInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @创建人 liuchunlin
 * @创建时间 16:50
 * @描述
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultInfo<String> jsonErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        ResultInfo<String> resultInfo = new ResultInfo<>();
        resultInfo.setMessage(e.getMessage());
        resultInfo.setCode(ResultInfo.ERROR);
        resultInfo.setData("Some Data");
        resultInfo.setUrl(req.getRequestURL().toString());
        return resultInfo;
    }

}